<template>
  <div class="hyzxpj_box">
    <div class="hyzxpj_box_tab">
      <div class="zxph_tab">{{ this.$route.meta.title }}</div>
    </div>
    <div class="shijian_zxpl">
      <span
        >开始时间：{{ listdata.start_date }} &nbsp;&nbsp; 截止时间：{{
          listdata.end_date
        }}</span
      >
    </div>
    <div class="box_zxpj">
      <div class="item_box_zxpj">
        <el-collapse v-model="activeNames">
          <el-collapse-item
            :title="item.name"
            :name="(index + 1).toString()"
            v-for="(item, index) in FormData"
            :key="index"
          >
            <list ref="childComp" :column="2" :list.sync="item.list"> </list>
          </el-collapse-item>
        </el-collapse>
      </div>
    </div>
    <div class="zxpj_button_box">
      <div class="zxpj_button_tj" style="margin: auto" v-if="buttonstate == 1">
        公示中
      </div>
      <div
        class="zxpj_button_tj bc"
        v-if="buttonstate == 0 || buttonstate == 4 || buttonstate == 6"
        @click="Submit(0)"
      >
        暂时保存
      </div>
      <div
        class="zxpj_button_tj"
        style="margin: auto"
        v-if="buttonstate == 3 || buttonstate == 2"
        @click="sq()"
      >
        申请修改
      </div>
      <div
        class="zxpj_button_tj"
        v-if="buttonstate == 0 || buttonstate == 4 || buttonstate == 6"
        @click="Submit(1)"
      >
        立即提交
      </div>
    </div>
  </div>
</template>
      
      <script>
import list from "../../components/list copy 2.vue";
export default {
  data() {
    return {
      activeNames: ["1"], //展开的页面
      listdata: {},
      FormData: [],
      buttonstate: 0,
    };
  },
  mounted() {
    // this.getinfo();
    this.getstate();
    this.getbutton();
  },
  components: {
    list: list,
  },
  methods: {
    /**
     * 申请修改
     */
    sq() {
      let that = this;
      let data = {};
      that.$http.post("credit/apply_edit", data).then((res) => {
        // if (res.code == 1) {
        that.$self
          .ts(res, 2)
          .then(() => {
            this.getbutton();
          })
          .catch(() => {
            this.getbutton();
          });
        // }
      });
    },
    /**
     * 获取按钮状态
     */
    getbutton() {
      let that = this;
      let data = {};
      that.$http.post("credit/check_status", data).then((res) => {
        if (res.code == 1) {
          that.buttonstate = res.data.status;
          that.listdata = {};
          that.FormData = [];
          this.getinfo();
        }
      });
    },
    //判断有没有缴费
    getmoney() {
      let that = this;
      let data = {};
      that.$http.post("mechanism/check_fee_status", data).then((res) => {
        if (res.data.status == 0 || res.data.status == 2) {
          that.$self
            .ts(res, 2)
            .then(() => {
              this.$router.push({
                path: "/hyjnhf",
              });
            })
            .catch(() => {
              this.$router.push({
                path: "/hyjnhf",
              });
            });
        }
      });
    },
    /**
     * 是否进入状态
     */
    getstate() {
      let that = this;
      let data = {};
      that.$http.post("credit/check_credit", data).then((res) => {
        if (res.code == 0) {
          console.log(res)
          that.$self
            .ts(res, 2)
            .then(() => {
              this.$router.push({
                path: "/hypjjl",
              });
            })
            .catch(() => {
              this.$router.push({
                path: "/hypjjl",
              });
            });
        } else {
          this.getmoney();
        }
      });
    },
    /**
     * 获取列表
     */
    getinfo() {
      let that = this;
      let data = {
        page: that.page,
      };
      that.$http.post("credit/credit_content", data).then((res) => {
        if (res.code === 1) {
          that.listdata = res.data;
          that.listdata.project.forEach((item, index) => {
            let formDataobj = {
              name: item.name,
              list: [],
            };
            item.content.forEach((ele, i) => {
              let obj = {};
              if (ele.type == "file") {
                obj = {
                  id: ele.id,
                  value: {
                    dialogVisible: false,
                    dialogImageUrl: "",
                  },
                  name: ele.name,
                  span: 2,
                  disabled: that.false,
                  type: "upload",
                  notes: ele.tip,
                  imglist: [],
                  disabled:
                    [0, 4, 6].indexOf(that.buttonstate) != -1 ? false : true,
                  showbutton:
                    [0, 4, 6].indexOf(that.buttonstate) != -1 ? false : true,
                };
                if (ele.value) {
                  let newimglist = ele.value.split(",");
                  for (let b = 0; b < newimglist.length; b++) {
                    newimglist[b] = that.$self.imgurl(newimglist[b]);
                  }
                  obj.imglist = that.$self.showimg(newimglist,ele.value_name);
                } else {
                  obj.imglist = [];
                }
              }
              if (ele.type == "input") {
                obj = {
                  id: ele.id,
                  value: ele.value,
                  name: ele.name,
                  span: 2,
                  isp: ele.tip,
                  disabled:
                    [0, 4, 6].indexOf(that.buttonstate) != -1 ? false : true,
                  type: "input",
                };
              }
              if (ele.type == "select") {
                obj = {
                  id: ele.id,
                  value: ele.value,
                  name: ele.name,
                  span: 2,
                  isp: ele.tip,
                  disabled:
                    [0, 4, 6].indexOf(that.buttonstate) != -1 ? false : true,
                  type: "select",
                  list: [],
                };
                // console.log(ele.selectvalue)
                for (let i = 0; i < ele.selectvalue.length; i++) {
                  // console.log(i)
                  let listobj = {
                    value: ele.selectvalue[i],
                    label: ele.selectvalue[i],
                  };
                  obj.list.push(listobj);
                }
              }
              if (!that.$self.pdobj(obj)) {
                formDataobj.list.push(obj);
              }
            });
            that.FormData.push(formDataobj);
          });

          // console.log(that.FormData);
        }
      });
    },
    Submit(type) {
      let that = this;
      let arr = [];
      that.FormData.forEach((item, index) => {
        item.list.forEach((ele, i) => {
          let obj = {};
          if (ele.type == "upload") {
            // console.log(ele.imglist, ele.id);

            let imglist_arr = [];
            ele.imglist.forEach((imgitem, y) => {
              // 判断是否是编辑
              let path;
              if (imgitem.response) {
                path = imgitem.response.data.url;
              } else {
                const url = new URL(imgitem.url);
                path = url.pathname;
              }
              imglist_arr.push(path);
            });

            obj = {
              id: ele.id,
              value: imglist_arr.join(","),
            };
          } else {
            // console.log(ele.value,ele.id)
            obj = {
              id: ele.id,
              value: ele.value,
            };
          }
          arr.push(obj);
        });
      });

      // console.log(arr);
      let data = {
        type: type,
        ask: arr,
      };
      that.$http.post("credit/credit_save", data).then((res) => {
        that.$self.ts(res, 2);
      });
    },
    //  ==
  },
};
</script>
      <style>
.hyzxpj_box {
  background: #ffffff;
  border-radius: 0.125rem;
  box-shadow: 1px 1px 3px 2px rgba(0, 0, 0, 0.15);
  margin: 0.125rem 0.025rem 0.3rem 0.625rem;
}
.hyzxpj_box_tab {
  border-bottom: solid 0.0375rem #1954a4;
  display: flex;
  align-items: center;
  height: 0.75rem;
  padding-left: 0.25rem;
  box-sizing: border-box;
}

.zxph_tab {
  border-left: solid 0.075rem #1954a4;
  font-size: 0.25rem;
  font-weight: 400;
  color: #1954a4;
  padding-left: 0.2125rem;
  box-sizing: border-box;
}
.shijian_zxpl {
  font-size: 0.25rem;
  font-weight: 400;
  color: #cd0000;
  height: 0.7875rem;
  display: flex;
  align-items: center;
  padding: 0.25rem;
  box-sizing: border-box;
}
.box_zxpj {
  padding: 0 0.275rem 0.5rem 0.275rem;
  margin-bottom: 0.075rem;
}
.item_box_zxpj .el-collapse-item__header {
  height: 0.55rem;
  background: #1954a4;
  font-size: 0.2rem;
  font-weight: bold;
  color: #ffffff;
  padding-left: 0.3875rem;
  box-sizing: border-box;
}
.item_box_zxpj .el-collapse-item__content {
  padding-bottom: 0.4875rem;
}
.hygxin tbody:first-child .el-input__inner {
  width: 360px;
}
.hygxin .my-label_jb {
  width: 2.35rem;
}
.nbglzd .my-label_jb {
  width: 1.4rem;
}
.item_box_zxpj .el-collapse-item__wrap {
  border-bottom: none !important;
}
.zxpj_button_box {
  display: flex;
  width: 6.875rem;
  justify-content: space-between;
  margin: auto;
  padding-bottom: 0.5rem;
}
.zxpj_button_tj {
  width: 3.25rem;
  height: 0.5rem;
  background: #1954a4;
  border-radius: 0.05rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.2rem;
  font-weight: 400;
  color: #ffffff;
  cursor: pointer;
}
.zxpj_button_tj:hover {
  background: #1f5fb8;
}
.bc {
  background: #fca204;
}
.bc:hover {
  background: #e9a125;
}
</style>
      